/**
 * 功能描述 列表准备数据
 */
define(function (require, exports, module) {
    var aw = require("ajaxwrapper");
    var store = require("store");
	var activeUser = store.get("user");
    var chargeFetchProperties = require("../constant/chargeFetchProperties")

    module.exports = {
    		queryChargeData : function(data, widget){
    			aw.ajax({
    				url : "api/signupcharge/queryplan",
    				data : {
    					"signUpRegister.planItemGroup.servicePoint.pkServicePoint" : data.pkServicePoint,
    					"signUpRegister.planItemGroup.planItem.pkPlanItem" : data.pkPlanItem,
    					"validatePrivilege" : false,
    					fetchProperties : chargeFetchProperties.fetchProperties
    				},
    				dataType : "json",
    				success : function(datas){
    					var data2=[];
    					var totalAmount = 0;
    					if(datas){
    						for(var i = 0; i < datas.length; i++){
    							var object=datas[i].signUpCharge;
    							object["refund"]=datas[i].refund;
    							if(!datas[i].refund){
    								totalAmount += datas[i].signUpCharge.payable;
    							}
    							if(datas[i].signUpCharge.payable == null){
    								object.payable = datas[i].signUpCharge.signUpRegister.planItemGroup.payable;
    								object.chargeDate = moment().format("YYYY-MM-DD");
    								object.operator = {
    										pkUser : activeUser.pkUser,
    										name : activeUser.name
    								}
    								totalAmount += datas[i].signUpCharge.payable;
    							}
    							data2.push(object);
//    							if(datas[i].operator){
//    								datas[i].operator.pkUser = activeUser.pkUser;
//    								datas[i].operator.name = activeUser.name;
//    				        	}else{
//    				        	}
    						}
    					}
    					
    					widget.get("form").setValue("totalAmount", totalAmount.toFixed(2));
    					widget.get("editgrid").setData(data2);
    					widget.get("detailgrid").setData(data2);
						
    					$('#memberChargeEditGrid .J-grid-table tr:first td:eq(7)').click();

    				}
    			})
    		}
    };
});
